<?php
class selValideurForm extends BaseForm
{
  public function configure()
  {
  	$this->setWidgets(array('valideur' => new sfWidgetFormChoice(array('multiple' => false,
							  'expanded' => false,
							  'choices'  => array()))));
	$this->getWidgetSchema()->setFormFormatterName('edsl');
    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
  }

  public function setValideurs($valideur, $titre ){
  	$q = Doctrine::getTable('lienvalideurpersonne')
	 		->createQuery('a')
	 		->select('a.id, b.name')
	 		->innerJoin('a.personnes b')
	 		->addWhere('a.id_valideur='.$valideur->id)
	 		->addOrderBy('b.name');
	$records = $q->execute(); 		
	$valideurs = array(''=>'Veuillez s&eacute;lectionner une valeur...');
	foreach($records as $item){
		$valideurs[$item->id] = $item->personnes->name;
	}
  	$this->widgetSchema['valideur'] =new sfWidgetFormChoice(array('multiple' => false,
							  'expanded' => false,
							  'choices'  => $valideurs));
	$this->offsetGet('valideur')->getWidget()->setAttributes(array(
			'class'=> "form combobox",
	    	'tmt:required'=> "true",
			'tmt:invalidindex'=> "0",
			'tmt:errorclass'=> "error",
			'tmt:message'=> "Champ obligatoire",
			));

	$helps=$this->widgetSchema->getHelps();
  	$helps['valideur']=' ';
  	$this->widgetSchema->setHelps($helps);	
  	
  	$labels=$this->widgetSchema->getLabels();
  	$labels['valideur']=$titre;
  	$this->widgetSchema->setLabels($labels);  
  }
  
}